package com.taotao.solon.uid;

import com.baidu.fsg.uid.impl.CachedUidGenerator;
import com.baidu.fsg.uid.worker.DisposableWorkerIdAssigner;
import com.baidu.fsg.uid.worker.dao.WorkerNodeDAO;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;

/**
 * <p>
 *
 * </p>
 *
 * @author fanbeibei
 * @version 1.0.0
 * @date 2025/4/23 14:30
 */
@Configuration
public class UidSolonConfig {

    @Inject("${uid-generator.time-bits:29}")
    private int timeBits;

    @Inject("${uid-generator.worker-bits:21}")
    private int workerBits;
    @Inject("${uid-generator.seq-bits:13}")
    private int seqBits;

    @Inject("${uid-generator.epoch-str:2025-01-01}")
    private String epochStr;
    @Inject("${uid-generator.boost-power:3}")
    private int boostPower;
    @Inject("${uid-generator.padding-factor:50}")
    private int paddingFactor;


    @Bean
    public CachedUidGenerator cachedUidGenerator(@Inject DisposableWorkerIdAssigner disposableWorkerIdAssigner) {
        CachedUidGenerator cug = new CachedUidGenerator();
        cug.setWorkerIdAssigner(disposableWorkerIdAssigner);
        cug.setTimeBits(timeBits);
        cug.setWorkerBits(workerBits);
        cug.setSeqBits(seqBits);
        cug.setEpochStr(epochStr);
        cug.setBoostPower(boostPower);
        cug.setPaddingFactor(paddingFactor);
        return cug;
    }


    @Bean
    public DisposableWorkerIdAssigner disposableWorkerIdAssigner(@Inject WorkerNodeDAO workerNodeDAO) {
        DisposableWorkerIdAssigner d = new DisposableWorkerIdAssigner();
        d.setWorkerNodeDAO(workerNodeDAO);
        return d;
    }

}
